package com.aaa.cs.controller;

import com.aaa.common.util.Result;
import com.aaa.common.util.ResultStatus;
import com.aaa.cs.entity.CarInsurance;
import com.aaa.cs.service.CarInsuranceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (CarInsurance)表控制层
 *
 * @author makejava
 * @since 2021-01-22 20:24:45
 */
@RestController
@RequestMapping("carInsurance")
@ApiOperation("carInsurance控制器")
public class CarInsuranceController {
    /**
     * 服务对象
     */
    @Resource
    private CarInsuranceService carInsuranceService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("单个对象查询")
    public Result selectOne(Integer id) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.carInsuranceService.queryById(id));
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @PostMapping("queryAll")
    public Result queryAll(Integer pageNo, Integer pageSize, @RequestBody CarInsurance carInsurance) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.carInsuranceService.queryAll(pageNo, pageSize, carInsurance));
    }

    /**
     * 新增数据
     *
     * @param carInsurance 实例对象
     * @return 实例对象
     */
    @PostMapping("insert")
    public Result insert(@RequestBody CarInsurance carInsurance) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.carInsuranceService.insert(carInsurance));
    }

    /**
     * 修改数据
     *
     * @param carInsurance 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public Result update(@RequestBody CarInsurance carInsurance) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.carInsuranceService.update(carInsurance));
    }

    /**
     * 通过主键删除数据
     *
     * @param carInsuranceId 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    public Result deleteById(Integer carInsuranceId) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.carInsuranceService.deleteById(carInsuranceId));
    }
}